<template>
  <div class="dashboard-container">
    <div class="dashboard-text">欢迎: {{ name }}</div>
    <el-divider></el-divider>
    <el-alert title="树莓派数据概况" type="success" :closable="false">
    </el-alert>
        <br>
    <div class="chart">
      <my-echarts :options="options" :width="width"></my-echarts>
      <my-echarts :options="options1" :width="width"></my-echarts>
    </div>

    <!-- <el-button @click="changeWidth">改变宽度</el-button>
    <el-button @click="changeOption">改变option</el-button> -->
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import MyEcharts from "./MyEcharts.vue";
import { options2, options1 } from "../../options";
import { getChartList } from "@/api/dashboard";

export default {
  name: "Dashboard",
  components: {
    MyEcharts,
  },
  computed: {
    ...mapGetters(["name"]),
  },
  data() {
    return {
      options: options2,
      options1: options1,
      width: "700px",
      chartData: [],
      Abscissa: [],
      Ordinate: [],
    };
  },
  methods: {
    initData() {
      // this.listLoading = true
      getChartList().then((response) => {
        for (let k in response.data) {
          this.chartData.push({
            name: k,
            value: response.data[k],
          });
          this.Abscissa.push(k);
          this.Ordinate.push(response.data[k]);
        }
        this.options.series[0].data = this.chartData;
        this.options1.xAxis.data = this.Abscissa;
        this.options1.series[0].data = this.Ordinate;
      });
    },
  },
  created() {
    this.initData();
  },
};
</script>

<style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
.chart {
  display: flex;
}
</style>
